package com.yunatt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunatt.mapper.RecordsMapper;
import com.yunatt.model.RecordsEntity;
import com.yunatt.service.RecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class RecordsServiceImpl implements RecordsService {
    @Autowired
    private RecordsMapper recordsMapper;
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return recordsMapper.deleteById(id);
    }

    @Override
    public int insert(RecordsEntity record) {
        return recordsMapper.insert(record);
    }

    @Override
    public int insertSelective(RecordsEntity record) {
        return recordsMapper.insert(record);
    }

    @Override
    public RecordsEntity selectByPrimaryKey(Integer id) {
        return recordsMapper.selectById(id);
    }

    @Override
    public int updateByPrimaryKeySelective(RecordsEntity record) {
        return recordsMapper.updateById(record);
    }

    @Override
    public int updateByPrimaryKey(RecordsEntity record) {
        return recordsMapper.updateById(record);
    }

    @Override
    public List<RecordsEntity> selectAllRecords() {
        return  recordsMapper.selectAllRecords();
    }

    @Override
    public List<RecordsEntity> selectUserRecords(Long enrollId) {
        QueryWrapper<RecordsEntity> recordsEntityQueryWrapper = new QueryWrapper<>();
        recordsEntityQueryWrapper.lambda().eq(RecordsEntity::getEnrollId, enrollId);
        return recordsMapper.selectList(recordsEntityQueryWrapper);
    }
}
